package com.ruoyi.standingbook.evaluate.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.evaluate.domain.bo.EvaluateBo;
import com.ruoyi.standingbook.evaluate.domain.vo.EvaluateVo;
import com.ruoyi.standingbook.evaluate.service.IEvaluateService;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;

/**
 * 市环境测评
 *
 * @author cc
 * @date 2023-04-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/evaluate")
public class EvaluateController extends BaseController {

    private final IEvaluateService iEvaluateService;

    /**
     * 查询市环境测评列表
     */
    @SaCheckPermission("evaluate:evaluate:list")
    @GetMapping("/list")
    public TableDataInfo<EvaluateVo> list(EvaluateBo bo, PageQuery pageQuery) {
        return iEvaluateService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出市环境测评列表
     */
    @SaCheckPermission("evaluate:evaluate:export")
    @Log(title = "市环境测评", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EvaluateBo bo, PageQuery pageQuery, HttpServletResponse response) {
    	pageQuery.setPageSize(10000);
        TableDataInfo<EvaluateVo> list = iEvaluateService.queryPageList(bo, pageQuery);
        ExcelUtil.exportExcel(list.getRows(), "市环境测评", EvaluateVo.class, response);
    }

    /**
     * 获取市环境测评详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("evaluate:evaluate:query")
    @GetMapping("/{id}")
    public R<EvaluateVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iEvaluateService.queryById(id));
    }

    /**
     * 新增市环境测评
     */
    @SaCheckPermission("evaluate:evaluate:add")
    @Log(title = "市环境测评", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EvaluateBo bo) {
        return toAjax(iEvaluateService.insertByBo(bo));
    }

    /**
     * 修改市环境测评
     */
    @SaCheckPermission("evaluate:evaluate:edit")
    @Log(title = "市环境测评", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EvaluateBo bo) {
        return toAjax(iEvaluateService.updateByBo(bo));
    }

    /**
     * 删除市环境测评
     *
     * @param ids 主键串
     */
    @SaCheckPermission("evaluate:evaluate:remove")
    @Log(title = "市环境测评", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iEvaluateService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
